<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Kalnoy\Nestedset\NodeTrait;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Spatie\Permission\Models\Role as SpatieRole;
use Illuminate\Database\Eloquent\SoftDeletes;

class Role extends SpatieRole
{
    use SoftDeletes;
    use NodeTrait;
    protected $dates = ['deleted_at'];
    protected $casts = [
        'is_role' => 'boolean',
    ];
    protected $fillable = ['name','is_role','parent_id'];

    public function getIdAndNameToArray(){
        $res = $this::all()->toArray();
        $arr_Array = array_reduce($res,function(&$arr_Array,$v){
            $arr_Array[$v['id']] = $v['name'];
            return $arr_Array;
        });
        return $arr_Array;
    }

    public function users(): MorphToMany
    {
        return parent::users(); // TODO: Change the autogenerated stub
    }
}
